# Maintainer: Sebastian Ehlert <awvwgk@disroot.org>

_realname=fpm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.5.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
pkgdesc="Fortran package manager (mingw-w64)"
url="https://github.com/fortran-lang/fpm"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-fortran"
             "git")
optdepends=("git: Support for fetching projects with git")
options=('strip')
license=('MIT')
source=(${_realname}-${pkgver}.zip::"${url}/releases/download/v${pkgver}/fpm-${pkgver}.zip"
        ${_realname}-${pkgver}.F90::"${url}/releases/download/v${pkgver}/fpm-${pkgver}.F90")
sha256sums=('e4a06956d2300f9aa1d06bd3323670480e946549617582e32684ded6921a921e'
            '53bba4d3d09d875d513ed4309a3defe414fa727dbcdeb38e4fdcf094e19c0257')
noextract=(${_realname}-${pkgver}.F90)

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  local _build="build_${CARCH}"
  local _fc="${MINGW_PREFIX}/bin/gfortran"

  mkdir -p "${_build}/bootstrap"
  "${_fc}" -J "${_build}/bootstrap" -o "${_build}/bootstrap/fpm" ${srcdir}/${_realname}-${pkgver}.F90

  "${_build}/bootstrap/fpm" install \
    --compiler "${_fc}" \
    --flag "-g -O3 -fbacktrace -fopenmp" \
    --prefix "${_build}"
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  install -Dm755 build_${CARCH}/bin/fpm "${pkgdir}"${MINGW_PREFIX}/bin/fpm
  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
